package cn.cookyfly.dailyreview.client;


public class Review {
	
	public static String BEGINING = "BEGINING";
	public static String END = "END";

	private static int current = 1;
	private static final String[] items = {
		BEGINING, 
		"节制", // No.1
		"沉默", // No.2
		"秩序", // No.3
		"果断", // No.4
		"节俭", // No.5
		"勤奋", // No.6
		"诚恳", // No.7
		"公正", // No.8
		"中庸", // No.9
		"清洁", // No.10
		"平静", // No.11
		"纯洁", // No.12
		"谦逊", // No.13
		"诫除: 中国式虚伪", // No.14
		END
	};
	
	private static String[] contents = new String[items.length];
	
	private static int nextOne() {
		int next = current + 1;
		if (isAvailable(next)) current++;
		return next;
	}
	
	private static int previousOne() {
		int next = current - 1;
		if (isAvailable(next)) current--;
		return next;
	}
	
	private static boolean isAvailable(int index) {
		if ((index > 0) && (index < 15)) return true;
		else return false;
	}
	
	private static boolean isInRange(int index) {
		if ((index < 0) || (index >= items.length)) return false;
		else return true;
	}
	
	private static String getItemFormated(int index) {
		String item = getItem(index);
		if (isAvailable(index)) item = index + ". " + item;
		return item;
	}

	public static int getItemsNumber() {
		return items.length - 2;
	}
	
	public static String[] getAllItems() {
		String[] itemsClone = new String[items.length - 2];
		for (int index = 1; index < items.length - 1; index++)
			itemsClone[index] = items[index];
		return itemsClone;
	}

	public static String getCurrentItem() {
		return getItemFormated(current);
	}
	
	public static String getNextItem() {
		return getItemFormated(current + 1);
	}
	
	public static String getPreviousItem() {
		return getItemFormated(current - 1);
	}
	
	public static String nextItem() {
		return getItemFormated(nextOne());
	}
	
	public static String previousItem() {
		return getItemFormated(previousOne());
	}

	public static boolean hasNext() {
		return (current < 14);
	}
	
	public static boolean hasPrevious() {
		return (current > 1);
	}
	
	public static String getItem(int index) {
		return isInRange(index) ? items[index] : null;
	}

	public static int getIndex(String item) {
		for (int index = 0; index < items.length; index++) {
			if (items[index].equals(item))
				return index;
		}
		return -1;// not found
	}

	public static boolean updateCurrentContent(String text) {
		if (!isAvailable(current)) return false;
		contents[current] = text;
		return true;
	}

	public static String getCurrentContent() {
		if (!isAvailable(current)) return null;
		return contents[current];
	}
	
	public static String[] getAllContent() {
		return contents;
	}
	
}
